﻿using CommunityToolkit.Mvvm.DependencyInjection;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Highlighting;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using XiaFControl.Controls;
using XiaFControl.Data.Enum;
using XiaFControl.Data.Info;
using XiaFControl.Demo.Common;
using XiaFControl.Themes;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace XiaFControl.Demo
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : XiaFWindow
    {
        MainViewModel viewModel;
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = Ioc.Default.GetRequiredService<MainViewModel>();
            this.Loaded += MainWindow_Loaded;
            this.Closing += MainWindow_Closing;
        }

        private async void MainWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
        {
            var result = XiaFControl.Controls.MessageBox.Confirm("是否退出程序？");
            if (result == System.Windows.MessageBoxResult.Cancel)
            {
                e.Cancel = true;
            }
        }

        private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            viewModel = this.DataContext as MainViewModel;
            viewModel.TextEditor = textEditor;
            //var themeDir = Application.Current.Resources.MergedDictionaries.FirstOrDefault(x=>x is Theme);
            //if (themeDir != null && themeDir is Theme theme)
            //{
            //    theme.Skin = SkinType.Dark;
            //}
        }
    }
}